var LOG = LOG ||{};
/**
 * 日志管理-问题单处理日志
 */
LOG.problem = Ext.extend(Ext.Panel,{
	closable:true
	,width:'100%'
	,initComponent:function(){
		this.tbar = this.buildBbar(this);
		var gp = new LOG.problem.gridPanel();
		this.items = [gp];
		this.formPanel = new LOG.problem.searchPanel({thisGrid:gp});
		LOG.problem.superclass.initComponent.call(this);
	}
	,buildBbar: function(mp) {
   		return [{
   				text: "按条件查询",
   				handler:function(btn){
   					var tform = btn.ownerCt.ownerCt.formPanel;
   	    			tform.show();
   				},
    			iconCls: 'ico-dot-search'
	   		}
   			,{xtype:'spacer',width:30}
   			,{
   				text: "删除日志",
   				handler:this.deleteLog,
    			iconCls: 'ico-task-delete'
	   		}
//   			,{
//   				text: "数据导出",
//   				handler:this.exportData,
//    			iconCls: 'ico-dot-report'
//	   		}
   			] ;
   	}
	,deleteLog:function(btn) {
   		var gp = btn.ownerCt.ownerCt.items.get(0) ;
   		var rows= gp.getSelectionModel().getSelections(); 
   		if(rows.length==0) {
   			 Ext.Msg.alert("提示", "请选择要操作的日志!");
   			 return ;
   		}
   		var ids = "";
   		for(var i=0 ;i<rows.length;i++) {
   			if(i==0) {
   				ids = rows[i].data['TASK_SEQ'] ;
   			}else{
   				ids = ids +","+rows[i].data['TASK_SEQ'] ;
   			}
   		}
   		Ext.MessageBox.confirm("确认", "确认要删除这些日志吗?", function(btn) {
					if (btn == "yes") {
						Ext.Ajax.request( {
							waitMsg : '正在执行  ',
							method : 'POST',
							params : {
								ids:ids 
							},
							url : 'logp_delProblemLog.action',
							scope : this,
							success : function(request) {
								var Result=Ext.decode(request.responseText);
								if(Result.success) {
									gp.getStore().reload();
								} else {
									 Ext.Msg.alert("错误",Result.info );
								}
							},
							failure : function() {
								Ext.Msg.alert("错误", "与后台联系的时候出现了问题");
							}
						});
						
					}
				});
   	}
});

LOG.problem.conditions = "";

LOG.problem.gridPanel = Ext.extend(Ext.grid.GridPanel,{
	initComponent : function(){
		var thisGrid = this;
   	 	var selectMode=new Ext.grid.CheckboxSelectionModel({
					dataIndex: "TASK_SEQ",
	                sortable: false,
	                singleSelect:false,
	                width:20
				});
   	 	this.recordStart = 1 ;
		var rn = new　Ext.grid.RowNumberer({
		　　header　:　"序号",
		　　width　:　35,
		　　renderer:function(value,metadata,record,rowIndex){
		　　　return　　thisGrid.recordStart　+　rowIndex;
		　　}
		});
   	    var problemStore =new Ext.data.JsonStore({
	         totalProperty:'totalProperty'
        	 ,url:'logp_getProblemLog.action'
        	 ,fields:[ 'TASK_SEQ','TASK_ID','REGION_CODE','START_TIME',
        	 			'END_TIME','RUN_STAT','DEAL_STAT','DEAL_TIME' ]
        	 ,root:'root'
        });
   	    this.viewConfig = {
   	    	forceFit:true
   	    };
   	    this.store = problemStore;
		this.sm = selectMode;
		this.bbar = [new Ext.PagingToolbar({
					pageSize : 200,
					store : problemStore,
					displayInfo : true,
					displayMsg : '第 {0} - {1} 条  共 {2} 条',
					emptyMsg : "没有记录",
					listeners:{
						beforechange:function(pt,obj) {
							thisGrid.recordStart = obj.start+1 ;  
						}
					}
				})];
		this.columns = [selectMode
					,{
				        header:'流水号',
						sortable:true
						,dataIndex:"TASK_SEQ"
					},{
				        header:'任务ID',
						sortable:true
						,dataIndex:"TASK_ID"
					},{
				        header:'区域代码',
						sortable:true
						,dataIndex:"REGION_CODE"
					},{
				        header:'开始时间',
						sortable:true
						,dataIndex:"START_TIME"
					},{
				        header:'结束时间',
						sortable:true
						,dataIndex:"END_TIME"
					}
					,{
						header:'运行结果',
						sortable:true
						,dataIndex:"DEAL_STAT"
					}
					,{
						header:'处理状态',
						sortable:true,
						dataIndex:"PROCESS_INFO"
					}
					,{
						header:'处理时间',
						sortable:true,
						dataIndex:"DEAL_TIME"
					}
			];
		problemStore.load({
			params:{
				start:0,
				limit:200
			}
		});
		LOG.problem.gridPanel.superclass.initComponent.call(this);
	}
});

LOG.problem.formPanel = Ext.extend(Ext.form.FormPanel,{
		text:"表单",
		layout:"form",
		region : "center",
		labelAlign:"right",
		width:550,
		height:300,
		frame:true,
		initComponent:function(){

				this.items=[
							{fieldLabel : '任务id',
								name : 'taskId',
								xtype:"textfield",
								editable : true,
								emptyText:"请填写",
								anchor:"90%"
					    	}
							,{fieldLabel : '处理时间',
								name : 'dealTime',
								xtype:"datefield",
								editable : true,
								format:'Y-m-d',
								emptyText:"请选择",
								anchor:"90%"
					    	}
							,{fieldLabel : '处理状态',
								xtype:"combo",
								anchor:"90%",
								emptyText:"请选择",
								editable : false,
								name:"dealStat",
								anchor:"90%",
								triggerAction : 'all',
								store : [['0','未处理'],['1','已经处理'],['2','处理中'],['4','处理失败']]
					    	}
			];
			LOG.problem.formPanel.superclass.initComponent.call(this);
		}
});
/**
 * 查询面板
 */
LOG.problem.searchPanel = Ext.extend( Ext.Window,{
   		closeAction: 'hide',
		resizable:false,
		modal:true,
		width:550,
		height:350
   		,layout:"fit"
   		,title: "按条件查询流程生成日志"
   		,initComponent:function(){
			this.items = [new LOG.problem.formPanel()];
			LOG.problem.searchPanel.superclass.initComponent.call(this);
   		}
   		,buttonAlign :'center'
		,minButtonWidth:60
		,buttons:[{
			text:"确定",
			handler : function(btn){
				var a = btn.ownerCt.ownerCt.items.get(0);
			    var thisForm = a.getForm();
			    var taskId  = thisForm.findField('taskId').getValue();
			    var dealTime = thisForm.findField('dealTime').getValue();
				    dealTime = dealTime?dealTime.format('Ymd'):"";
			    var dealStat = thisForm.findField('dealStat').getValue();
			    var store = btn.ownerCt.ownerCt.thisGrid.getStore();
			    
//			    //保存条件
//			    LOG.problem.conditions =
//			    	'tsLOGuserLogin.eparchyCode='+eparchyCode+
//					'&tsLOGuserLogin.cityCode='+cityCode+
//					'&tsLOGuserLogin.startDate='+statDay+
//					'&tsLOGuserLogin.checkDate='+checkDate;
			    
			    btn.ownerCt.ownerCt.thisGrid.recordStart = 1;
			    store.baseParams = {
					'taskId':taskId,'dealTime':dealTime, 'dealStat':dealStat
				};
	
	            store.load({params:{start:0, limit:200}});
			    
			   btn.ownerCt.ownerCt.hide();//隐藏弹出页面
			}
		}, {
			text : '重置',
			handler : function() {this.ownerCt.ownerCt.form.reset();}
		}, {
			text : '取消',
			handler : function() {this.ownerCt.ownerCt.hide();}
		}]
});
